<template>
  <el-dialog title="批量修改" :close-on-click-modal="false" :visible.sync="visible" center>
    <el-button class="miui-dialog-close-btn" @click="visible = false">关闭页面</el-button>
    <el-form :model="dataForm" :rules="dataRule" ref="dataForm" label-width="80px">
      <el-row :gutter="15">
        <el-col :span="8">
          <el-form-item label="库存上限" prop="inventoryTop">
            <el-input v-model="dataForm.inventoryTop" placeholder="库存上限"></el-input>
          </el-form-item>
        </el-col>
        <el-col :span="8">
          <el-form-item label="库存下限" prop="inventoryFloor">
            <el-input v-model="dataForm.inventoryFloor" placeholder="库存下限"></el-input>
          </el-form-item>
        </el-col>
        <el-col :span="8">
          <el-form-item label="红色预警" prop="redAlert">
            <el-input v-model="dataForm.redAlert" placeholder="红色预警"></el-input>
          </el-form-item>
        </el-col>
      </el-row>
    </el-form>
    <span slot="footer" class="dialog-footer">
      <el-button @click="visible = false">取消</el-button>
      <el-button type="primary" @click="dataFormSubmit" :loading="ischeck" v-prevent-re-click>确定</el-button>
    </span>
  </el-dialog>
</template>

<script>
    import {warningSettingBatchEdit} from '@/api/eims/warning-setting'
    export default {
    data () {
      return {
				ischeck: false,
        visible: false,
        dataForm: {
          ids: [],
          inventoryTop: '',
          inventoryFloor: '',
          redAlert: ''
        },
        dataRule: {
          inventoryTop: [{ required: true, message: '库存上限不能为空', trigger: 'blur' }],
          inventoryFloor: [{ required: true, message: '库存下限不能为空', trigger: 'blur' }],
          redAlert: [{ required: true, message: '红色预警不能为空', trigger: 'blur' }]
        }
      }
    },
    methods: {
      init (id) {
        this.dataForm.ids = id
        this.visible = true
      },
      // 表单提交
      dataFormSubmit () {
				this.ischeck = true
        this.$refs['dataForm'].validate((valid) => {
          if (valid) {
            if(this.inventoryFloor > this.inventoryTop) {
							this.ischeck = false
              this.$message.warning('库存量下限不能大于库存量上限')
              return
            }
            if(this.redAlert > this.inventoryFloor) {
							this.ischeck = false
              this.$message.warning('库存量红色预警不能大于库存量下限')
              return
            }
            warningSettingBatchEdit(this.dataForm).then(response => {
              if(response.data.code == '0'){
                this.$message.success('修改成功')
                this.visible = false
                this.$emit('updateBatch')
              }else{
                this.$message.error(response.data.msg)
              }
              this.ischeck = false
            }).catch(() => {
              this.ischeck = false
            })
          }else{
						this.ischeck = false
					}
        })
      }
    }
  }
</script>
